package com.fire.market.controller;

import com.fire.component.dto.SingleResponse;
import com.fire.component.extension.Assert;
import com.fire.market.promo.api.dto.PromoInfo;
import com.fire.market.promo.api.service.PromoQueryFrontService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * PromoQueryController
 *
 * @author zwd
 * @date 2021/7/21
 */
@RestController
@RequestMapping("/promo/query")
@Api(tags = "促销query服务")
public class PromoQueryController {
    @Reference
    PromoQueryFrontService promoQueryFrontService;

    /**
     * 根据商品的id->秒杀详情(即将进行或者正在进行)
     */
    @GetMapping(value = "detail/{itemId}")
    @ApiOperation(value = "促销商品信息", notes = "查询促销商品信息")
    @ApiImplicitParam(name = "itemId", value = "商品id", required = true, dataType = "Integer")
    public SingleResponse<PromoInfo> queryPromo(@PathVariable("itemId") Integer itemId){
        Assert.notNull(itemId, "itemId is null");
        return SingleResponse.of(promoQueryFrontService.queryPromo(itemId).getData());
    }
}
